package com.terrynoya.fight.combat
{
	import flash.geom.Rectangle;

	public class Collisions
	{
		private var _rects:Array;
		
		public function Collisions()
		{
			this._rects = new Array();
		}
		
		public function get rects():Array
		{
			return _rects;
		}

		public function addRect(rect:Rectangle):void
		{
			this._rects.push(rect);
		}
		
		/**
		 * 2组多个矩形进行碰撞检测
		 * 一组中的任何一个和另一组的任何一个有碰撞返回true
		 * 一组中的所有矩形和另一个组的所有矩形都未碰撞，返回false
		 * @param rects1
		 * @param rects2
		 * @return 
		 * 
		 */		
		public static function hitTest(rects1:Array,rects2:Array):Boolean
		{
			var rlt:Boolean = false;
			for (var i:int = 0; i < rects1.length; i++) 
			{
				var isCollide:Boolean = false;
				var rect1:Rectangle = rects1[i];
				for (var j:int = 0; j < rects2.length; j++) 
				{
					var rect2:Rectangle = rects2[j];
					if(rect1.intersects(rect2))
					{
						isCollide = true;	
						break;
					}
				}
				if(isCollide)
				{
					rlt  = true;
					break;
				}
			}
			return rlt;
		}
	}
}